/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Control.ControlOwner;
import java.awt.Color;
import java.awt.Toolkit;
import java.util.Date;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Nicolas
 */
public class OwnerCreatePanel extends javax.swing.JPanel {
    
    ControlOwner co;
    private HPVAS father;
    
    public OwnerCreatePanel(HPVAS father) {
        initComponents();
        this.father = father;
        this.setVisible(true);
        co = new ControlOwner();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        create_button = new javax.swing.JButton();
        text_info = new javax.swing.JLabel();
        cancel_button = new javax.swing.JButton();
        name_text = new javax.swing.JTextField();
        lastName_text = new javax.swing.JTextField();
        birthPlace_text = new javax.swing.JTextField();
        ssn_text = new javax.swing.JFormattedTextField(createFormatter("###-##-####"));
        ano_text = new javax.swing.JFormattedTextField(createFormatter("####"));
        mes_text = new javax.swing.JFormattedTextField(createFormatter("##"));
        dia_text = new javax.swing.JFormattedTextField(createFormatter("##"));

        setMaximumSize(new java.awt.Dimension(465, 284));
        setMinimumSize(new java.awt.Dimension(465, 284));
        setPreferredSize(new java.awt.Dimension(465, 284));

        jLabel1.setText("Owner");

        jLabel2.setText("Name");

        jLabel3.setText("Last Name");
        jLabel3.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel3.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel3.setPreferredSize(new java.awt.Dimension(27, 14));

        jLabel4.setText("SSN");
        jLabel4.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel4.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel4.setPreferredSize(new java.awt.Dimension(27, 14));

        jLabel5.setText("BirthDate");
        jLabel5.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel5.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel5.setPreferredSize(new java.awt.Dimension(27, 14));

        jLabel6.setText("BirthPlace");
        jLabel6.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel6.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel6.setPreferredSize(new java.awt.Dimension(27, 14));

        create_button.setText("Create");
        create_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                create_buttonActionPerformed(evt);
            }
        });

        cancel_button.setText("Cancel");
        cancel_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancel_buttonActionPerformed(evt);
            }
        });

        lastName_text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lastName_textActionPerformed(evt);
            }
        });

        ssn_text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ssn_textActionPerformed(evt);
            }
        });

        ano_text.setText("Año");

        mes_text.setText("Mes");

        dia_text.setText("Dia");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(name_text, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
                            .addComponent(lastName_text)
                            .addComponent(birthPlace_text)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(dia_text, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(mes_text, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ano_text, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(ssn_text)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cancel_button, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                        .addComponent(create_button, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(text_info)
                .addContainerGap(56, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(text_info)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(name_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lastName_text, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(ssn_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ano_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mes_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dia_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(birthPlace_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(create_button)
                    .addComponent(cancel_button))
                .addContainerGap(61, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void create_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_create_buttonActionPerformed
        Date d = new Date(Integer.parseInt(ano_text.getText().trim()),Integer.parseInt(mes_text.getText()),Integer.parseInt(dia_text.getText()));
        System.out.println(name_text.getText().trim()+"1");
        System.out.println(lastName_text.getText().trim()+"2");
        System.out.println(ssn_text.getText()+"3");
        System.out.println(d+"4");
        System.out.println(birthPlace_text.getText().trim()+"5");
        co.crearOwner(name_text.getText().trim(), lastName_text.getText().trim(), ssn_text.getText(), d, birthPlace_text.getText().trim());
        father.setCurrent_panel(new MainPanel());
        father.change_panel();
    }//GEN-LAST:event_create_buttonActionPerformed

    private void cancel_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_buttonActionPerformed
        father.setCurrent_panel(new MainPanel());
        father.change_panel();
    }//GEN-LAST:event_cancel_buttonActionPerformed

    private void lastName_textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lastName_textActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lastName_textActionPerformed

    private void ssn_textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ssn_textActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ssn_textActionPerformed

    protected MaskFormatter createFormatter(String s) {
    MaskFormatter formatter = null;
    try {
        formatter = new MaskFormatter(s);
    } catch (java.text.ParseException exc) {
        System.err.println("formatter is bad: " + exc.getMessage());
        System.exit(-1);
    }
    return formatter;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField ano_text;
    private javax.swing.JTextField birthPlace_text;
    private javax.swing.JButton cancel_button;
    private javax.swing.JButton create_button;
    private javax.swing.JFormattedTextField dia_text;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField lastName_text;
    private javax.swing.JFormattedTextField mes_text;
    private javax.swing.JTextField name_text;
    private javax.swing.JFormattedTextField ssn_text;
    private javax.swing.JLabel text_info;
    // End of variables declaration//GEN-END:variables
}
